/** @format */

import { createRouter, createWebHistory } from 'vue-router';
import { routes } from './router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { useGlobalLoading } from '@/hooks/useLoading';

NProgress.configure({ showSpinner: false });
const routerBase = '/web';
const router = createRouter({
  history: createWebHistory(routerBase),
  linkActiveClass: 'act-two-div',
  routes: [...routes],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

router.beforeEach((to, from, next) => {
  useGlobalLoading().setGlobalLoading(true);

  next();
  // console.log(store._state.data.users.userType)
  // NProgress.start();
  // document.title = to.meta && to.meta.title ? to.meta.title : '商城';
  // const token = sessionStorage.getItem('token') || '';
  // const thePassRouter = [
  //   '/login',
  //   '/smslogin',
  //   '/index',
  //   '/register',
  //   '/',
  //   '/shop-list',
  //   '/shop-detail',
  // ];
  // if (thePassRouter.includes(to.path)) {
  //   next();
  // } else {
  //   if (token) {
  //     next();
  //   } else {
  //     next('/login');
  //   }
  // }
});

router.afterEach(() => {
  NProgress.done();
});

export default router;
